<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Gentelella Alela! | </title>

    <!-- Bootstrap -->
    <link href="vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="vendors/nprogress/nprogress.css" rel="stylesheet">
    <!-- Animate.css -->
    <link href="vendors/animate.css/animate.min.css" rel="stylesheet">
    <!-- Custom Theme Style -->
    <link href="build/css/custom.min.css" rel="stylesheet">
    <script type="text/javascript" src="vendors/select2/vendor/jquery-2.1.0.js"></script>
    <script type="text/javascript" src="js/tool/md5.js"></script>
</head>

<body class="login">
<div>
    <a class="hiddenanchor" id="signup"></a>
    <a class="hiddenanchor" id="signin"></a>
    <div class="login_wrapper">
        <div class="animate form login_form">
            <section class="login_content">
                <form action="/login" name="loginForm" id="loginForm">
                    <h1>登录</h1>
                    <div>
                        <input type="text" id="userName" name="userName" class="form-control" placeholder="Username"
                               required="required"/>
                    </div>
                    <div>
                        <input type="password" id="password" name="password" class="form-control" placeholder="Password"
                               required="required"/>
                    </div>
                    <div id="loginMsg" style="display: none">
                        <span id="loginMsgSpan"></span>
                    </div>
                    <div>
                        <a class="btn btn-default submit" href="javascript:login()">登录</a>
                        <a class="reset_pass" href="#">Lost your password?</a>
                    </div>
                </form>
            </section>
        </div>
    </div>
</div>
<script>
    function login() {
        var data = {};
        data.userName = $("#userName").val();
        data.password = hex_md5($("#password").val());

        $.ajax({
            url:"/login.do",
            data:data,
            type:"POST",
            success:function(respData){
                console.log(respData);
                if(respData && respData.code && respData.code == "success"){
                    window.location.href="/index";
                }else if(respData && respData.code){
                    // 错误信息显示
                    $("#loginMsg").css("display","block");
                    $("#loginMsgSpan").val(respData.msg);
                }else{
                    // TODO 弹窗显示异常
                }
            }
        })
    }
</script>
</body>
</html>